<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>

        </div><!-- end .row -->
    </div>
</div><!-- end #body -->


<footer>

    <?php
    const PATH = 'min.txt';
    $min_after = 0;
    $min_five_minutes = 0;
    $total = 0;

    if(file_exists(PATH)){
        $line = file(PATH)[1];
        $time = explode(',',$line);
        if(count($time) == 2){
            @$time = date('d',$time[1]);
            $currenrTime = date('d',time());
            if($time != $currenrTime)
                unlink(PATH);
        }
    }

    $f = fopen(PATH,"a");
    $size = filesize(PATH);
    $ip = $_SERVER['REMOTE_ADDR'];
    $time = time();
    $data = "\n$ip,$time;";

    if(flock($f,LOCK_EX)){
        fwrite($f,$data);
        flock($f,LOCK_UN);
    }
    fclose($f);


    $content = file_get_contents(PATH);
    $datas = explode(';',$content);


    for($i=0;$i<count($datas);$i++){
        $ds = explode(',',$datas[$i]);
        // var_dump($ds);
        if(count($ds) < 2)
            continue;
        $s = time() - intval($ds[1]);
        // echo $s;
        if($s < 60*5){
            $min_five_minutes++;
        }
        $total++;

    }


    session_start();
    //文件保存目录
    const PATH2 = 'online.txt';

    // 设置时长
    $online_time = 60;

    if(file_exists(PATH2))
        $file = file(PATH2);
    else
        $file = [];

    $f2 = fopen(PATH2,'w+');
    foreach($file as $line){
        if(substr_count($line,',') < 1)
            continue;
        $id = explode(',',$line)[1];
        $time = explode(',',$line)[2];
        // echo $id,' ',session_id();
        if($id == session_id())
            continue;
        if((time() - intval($time)) < $online_time)
            fwrite($f2,"$line\n");
    }


    $id = session_id();
    $time = time();
    $ip = $_SERVER['REMOTE_ADDR'];
    fwrite($f2,"$ip,$id,$time");

    $onlinec = 0;
    $onlinecp = file(PATH2);
    foreach ($onlinecp as $l){
        if(substr_count($l,',') >=1 )
            $onlinec++;
    }

    echo "<p>当前在线人数：$onlinec&nbsp;&nbsp;|&nbsp;&nbsp;五分内访问次数：$min_five_minutes&nbsp;&nbsp;|&nbsp;&nbsp;今天共 $total 人访问</p>";

    ?>


    <p>© <?php echo date('Y'),' '; $this->options->title() ?></p>
    <p>Theme EsMble By <a href="https://blog.jamiexu.cn">JamieXu</a> | Powered by <a href="http://www.typecho.org">Typecho</a></p>
</footer>

<?php //$this->footer(); ?>
</body>
</html>
